

#ifndef __ARGS_H
#define __ARGS_H


class Args
{
	typedef std::map<std::string,std::string> SettingsMap;
	typedef std::map<std::string,bool>		  SwitchMap;

	SettingsMap setting;
	SwitchMap	switch_;
	std::string progName;

public:

	Args(int argc, const char *argv[])
		:	progName(argv[0])
	{
		for(int i=1; i<argc; ++i)
			Add(argv[i]);
	}

	virtual ~Args() {
	}


	std::string GetProgName() const {

		return progName;
	}

	bool GetSwitch(const std::string &sw) const {

		SwitchMap::const_iterator it = switch_.find( sw );

		if(it != switch_.end())
			return it->second;

		return false;
	}

	int GetSettingAsInt(const std::string &sw) const {

		SettingsMap::const_iterator it = setting.find( sw );

		if(it != setting.end())
			return atoi( it->second.c_str() );

		return 0;
	}

	std::string GetSettingAsString(const std::string &sw) const {

		SettingsMap::const_iterator it = setting.find( sw );

		if(it != setting.end())
			return it->second;

		return "";
	}

private:

	void Add(const char * _opt) {

		std::string opt(_opt);

		size_t pos = opt.find("=");

		if(pos == std::string::npos)
			switch_[_opt] = true;
		else
			setting[ opt.substr(0,pos) ] = opt.substr(pos+1, opt.size() - (1+pos) );
	}
};

#endif /*** __ARGS_H ***/

